using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Order.Dto;
using JTZY.Model.Order;
using JTZY.Service.Order.IOrderService;
using JTZY.Admin.WebApi.Filters;
using JTZY.Service.Order;

//创建时间：2024-11-11
namespace JTZY.Admin.WebApi.Controllers.Order
{
    /// <summary>
    /// 售后单明细表
    /// </summary>
    [Verify]
    [Route("order/Corecmsbillaftersalesitem")]
    public class CorecmsbillaftersalesitemController : BaseController
    {
        /// <summary>
        /// 售后单明细表接口
        /// </summary>
        private readonly ICorecmsbillaftersalesitemService _CorecmsbillaftersalesitemService;

        public CorecmsbillaftersalesitemController(ICorecmsbillaftersalesitemService CorecmsbillaftersalesitemService)
        {
            _CorecmsbillaftersalesitemService = CorecmsbillaftersalesitemService;
        }

        /// <summary>
        /// 查询售后单明细表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsbillaftersalesitem:list")]
        public IActionResult QueryCorecmsbillaftersalesitem([FromQuery] CorecmsbillaftersalesitemQueryDto parm)
        {
            var response = _CorecmsbillaftersalesitemService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询售后单明细表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("getorderproducts")]
        [ActionPermissionFilter(Permission = "corecmsbillaftersalesitem:query")]
        public IActionResult GetCorecmsbillaftersalesitem(string afterSalesId)
        {

            long userId = HttpContext.GetUId();
            var response = _CorecmsbillaftersalesitemService.GetInfo(afterSalesId, userId);

            //var info = response.Adapt<List<CorecmsbillaftersalesitemDto>>();
            return SUCCESS(response);
        }

        /// <summary>
        /// 添加售后单明细表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsbillaftersalesitem:add")]
        [Log(Title = "售后单明细表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsbillaftersalesitem([FromBody] CorecmsbillaftersalesitemDto parm)
        {
            var modal = parm.Adapt<Corecmsbillaftersalesitem>().ToCreate(HttpContext);

            var response = _CorecmsbillaftersalesitemService.AddCorecmsbillaftersalesitem(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新售后单明细表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsbillaftersalesitem:edit")]
        [Log(Title = "售后单明细表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsbillaftersalesitem([FromBody] CorecmsbillaftersalesitemDto parm)
        {
            var modal = parm.Adapt<Corecmsbillaftersalesitem>().ToUpdate(HttpContext);
            var response = _CorecmsbillaftersalesitemService.UpdateCorecmsbillaftersalesitem(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除售后单明细表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsbillaftersalesitem:delete")]
        [Log(Title = "售后单明细表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsbillaftersalesitem([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsbillaftersalesitemService.Delete(idArr));
        }

    }
}